from interface.Memberiniterce1 import MemberInterface
from utile.sendmethod import SendMethod
# 添加购物车
# 获取当前会员的购物车列表

class CartInterface:
    def __init__(self, url, headers):
        self.url = url
        self.headers = headers

    # 添加购物车
    def cart_add(self, payload):
        method = 'post'
        url = self.url + '/cart/add'
        return SendMethod.send_method(method=method, url=url, json=payload, headers=self.headers)

    # 获取当前会员的购物车列表
    def car_get_list(self,payload):
        method = 'get'
        url = self.url + '/cart/list'
        return SendMethod.send_method(method=method, url=url,headers=self.headers,json=payload)


if __name__ == '__main__':
    url = 'http://47.108.206.100:8085'
    headers = MemberInterface(url).get_token('ymYM', 654321)
    # print(headers)
    cart = CartInterface(url, headers)
    payload = {
        "createDate": "2022-06-10T02:01:35.734Z",
        "deleteStatus": 0,
        "id": 0,
        "memberId": 1831,
        "memberNickname": "ymYM",
        "modifyDate": "2022-06-10T04:01:35.734Z",
        "price": 2699,
        "productAttr": '[{"key":"颜色","value":"黑色"},{"key":"容量","value":"32G"}]',
        "productBrand": "小米",
        "productCategoryId": 19,
        "productId": 27,
        "productName": "小米8 全面屏游戏智能手机 6GB+64GB 黑色 全网通4G 双卡双待",
        "productPic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180615/xiaomi.jpg",
        "productSkuCode": "201808270027001",
        "productSkuId": 98,
        "productSn": "7437788",
        "productSubTitle": "骁龙845处理器，红外人脸解锁，AI变焦双摄，AI语音助手小米6X低至1299，点击抢购",
        "quantity": 1
    }
    # print(cart.cart_add(payload))  # 调用添加购物车
    print(cart.car_get_list(payload))  #获取当前会员的购物车列表
    